.SUFFIXES: .asm

CC=nasm
LD=ld
RM=rm
CFLAGS=-f elf32 -g
LDFLAGS=-m elf_i386
SOURCES=cstring.asm FpuNum.asm IntNum.asm DateTime.asm syscall.asm Lexicon.asm Scanner.asm Syntact.asm PolishCa.asm Polishow.asm
TESTS=TestScan.asm TestLexi.asm ExprGrav.asm TestSynt.asm ExprCalc.asm 
OBJECTS=$(SOURCES:.asm=.o)
OBJS_TESTS=$(TESTS:.asm=.o)
EXECUTABLES=$(TESTS:.asm=)

all: $(SOURCES) $(TESTS) $(EXECUTABLES) TestCalc

clean:
	@echo "Cleaning"
	@$(RM) -f *.o *~ $(EXECUTABLES) TestCalc

.asm.o:
	@echo "Compiling $@"
	@$(CC) $(CFLAGS) $< -o $@

$(EXECUTABLES): $(OBJECTS) $(OBJS_TESTS) 
	@echo "Linking $@"
	@$(LD) $(LDFLAGS) $(OBJECTS) $@.o -o $@

test: TestCalc
	@echo
	@echo "Starting test..."
	@./TestCalc

TestCalc: TestCalc.o IntNum.o FpuNum.o cstring.o syscall.o PolishCa.o Syntact.o Lexicon.o Scanner.o
	@echo "Linking $@"
	@$(LD) $(LDFLAGS) TestCalc.o IntNum.o FpuNum.o cstring.o syscall.o PolishCa.o Syntact.o Lexicon.o Scanner.o -o $@
